package study.nzy.com.studydemo;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import study.nzy.com.studydemo.utils.MenuAdapter;
import study.nzy.com.studydemo.utils.MenuItem;
import study.nzy.com.studydemo.utils.ToastUtils;

public class MainActivity extends Activity {

    GridView gv_items;
    List<MenuItem> menuItems;
    Activity activity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        activity = this;
        gv_items = findViewById(R.id.gv_items);

        menuItems = new ArrayList<>();
        menuItems.add(new MenuItem(R.color.main_darkblue,R.string.main_znjj,R.drawable.icon_home));
        menuItems.add(new MenuItem(R.color.main_orangered,R.string.main_zncs,R.drawable.icon_shopping));
        menuItems.add(new MenuItem(R.color.main_blue,R.string.main_tqyb,R.drawable.icon_weather));
        menuItems.add(new MenuItem(R.color.main_orange,R.string.main_szzx,R.drawable.icon_settings));

        gv_items.setAdapter(new MenuAdapter(menuItems,this));
        gv_items.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                ToastUtils.showToast(getApplicationContext(),getString(menuItems.get(i).getTitle()));
                if (i == 0){
                    Intent intent = new Intent(activity,ListActivity.class);
                    startActivity(intent);
                }
                else if(i==3){
                    Intent intent = new Intent(activity,SettingActivity.class);
                    startActivity(intent);
                }
                else if(i==2) {
                    Intent intent = new Intent(activity,RoomActivity.class);
                    startActivity(intent);
                }
            }
        });
    }
}

